package com.mysite.angular.common;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class BaseController {

	protected Logger logger = Logger.getLogger(this.getClass());
	
	protected Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();

	/**
	 * 获取参数列表
	 * 
	 * @author congg
	 * @since 2017年5月25日 下午2:20:34
	 * @param request
	 * @return
	 */
	protected Map<String, Object> getParameterMap(HttpServletRequest request) {
		HashMap<String, Object> searchMap = new HashMap<String, Object>();
		Map<String, String[]> map = request.getParameterMap();
		for (Map.Entry<String, String[]> entry : map.entrySet()) {
			String key = entry.getKey();
			String[] m = entry.getValue();
			if (m.length == 1) {
				searchMap.put(key, m[0]);
			} else {
				searchMap.put(key, Arrays.asList(m));
			}
		}
		return searchMap;
	}
}
